package com.lp.guidepage.ui.fragment;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.lp.guidepage.R;


/**
 * admin
 * 2019/1/11
 * content :
 */
public class LaunchFragment extends BaseFragment {

    private int flag;
    private ImageView launchJump;
    private RelativeLayout launchBg;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.launch_fragment, container, false);
        launchJump = view.findViewById(R.id.launch_jump);
        launchBg = view.findViewById(R.id.launch_bg);
        initData();
        return view;
    }

    public LaunchFragment setFlag(int flag) {
        this.flag = flag;
        return this;
    }

    @Override
    protected void lazyLoad() {

    }

    private void initData() {
        switch (flag) {
            case 0:
                launchBg.setBackgroundResource(R.mipmap.launch_img_1);
                break;
            case 1:
                launchBg.setBackgroundResource(R.mipmap.launch_img_2);
                break;
            case 2:
                launchJump.setVisibility(View.VISIBLE);
                initShotAnim(launchJump);
                launchBg.setBackgroundResource(R.mipmap.launch_img_3);
                break;
        }
        launchJump.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent().setClassName(getContext(), "com.xunyoutest.shop.ui.activity.SplashActivity"));
                getActivity().finish();
            }
        });
    }
    private void initShotAnim(ImageView iv) {
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator animatorX = ObjectAnimator.ofFloat(iv, "scaleX", 1f, 1.2f, 1f);
        ObjectAnimator animatorY = ObjectAnimator.ofFloat(iv, "scaleY", 1f, 1.2f, 1f);
        animatorX.setRepeatCount(-1);
        animatorY.setRepeatCount(-1);
        animatorSet.play(animatorX).with(animatorY);
        animatorSet.setDuration(600).start();
    }
}
